package com.study.sxc.Dao;

import com.study.sxc.Entity.Lab;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface ILabDao {
    @Select({
        "<script>",
        "SELECT lab_id AS labId, lab_name AS labName, location, capacity",
        "FROM Labs",
        "WHERE lab_id IN",
        "<foreach collection='list' item='id' open='(' separator=',' close=')'>",
        "#{id}",
        "</foreach>",
        "</script>"
    })
    List<Lab> getLabs(List<Integer> ids);

    @Insert("INSERT INTO Labs (lab_name, location, capacity) VALUES (#{labName}, #{location}, #{capacity})")
    @Options(useGeneratedKeys = true, keyProperty = "labId")
    int addLab(Lab lab);

    @Update("UPDATE Labs SET lab_name = #{labName}, location = #{location}, capacity = #{capacity} WHERE lab_id = #{labId}")
    int updateLab(Lab lab);

    @Delete("DELETE FROM Labs WHERE lab_id = #{id}")
    int deleteLab(Integer id);

    @Select("SELECT lab_id AS labId, lab_name AS labName, location, capacity FROM Labs WHERE lab_id = #{id}")
    Lab getLabById(Integer id);

    @Select("SELECT lab_id AS labId, lab_name AS labName, location, capacity FROM Labs")
    List<Lab> getAllLabs();
}
